export default {
	data() {
		return {
			show: false,
			title: '修改密码',
			userInfo: {},
			phone: '',
			oldPassword: '',
			newPassword: '',
			showModal:false,
			showContent:'',
		}
	},
	onLoad(){
		this.$api.getUserInfo().then((res) => {
			if(res.data.returnCode == '200') {
				this.userInfo = res.data.result
			}
			
		})
	},
	methods:{
		modify(){
			this.show = true;
		},
		confirm() {
			let passCode = /(?!.*\s)(?!^[\u4E00-\u9FA5]+$)(?!^[a-zA-Z]+$)(?!^[\d]+$)(?!^[^\u4E00-\u9FA5a-zA-Z\d]+$)^.{6,20}$/
			if (!(passCode.test(this.newPassword)) || this.newPassword == '') {
				this.showModal = true
				this.showContent = '密码不少于6位数，且字母、数字和符号至少包含两种。'
				return;
			}		
			if(this.oldPassword == '') {
				this.showModal = true
				this.showContent = '原密码不能为空'
				return;
			}
			const phone = this.userInfo.phone;
			this.$api.updatePassword({phone:phone,newPassword:this.newPassword,oldPassword:this.oldPassword}).then((res) => {
				if(res.data.returnCode == '200') {
					uni.navigateTo({
						url:'/pages/login/login'
					})
				}
			})
		},
		newPasswordBlur() {
			let passCode = /(?!.*\s)(?!^[\u4E00-\u9FA5]+$)(?!^[a-zA-Z]+$)(?!^[\d]+$)(?!^[^\u4E00-\u9FA5a-zA-Z\d]+$)^.{6,20}$/
			if (!(passCode.test(this.newPassword))) {
				this.showModal = true
				this.showContent = '密码不少于6位数，且字母、数字和符号至少包含两种。'
				return;
			}
		},
		oldPasswordBlur(){
			if(this.oldPassword == '') {
				this.showModal = true
				this.showContent = '原密码不能为空'
				return;
			} else {
				const phone = this.userInfo.phone;
				this.$api.verificationPassword({phone:phone,oldPassword:this.oldPassword}).then((res) => {
					if(res.data.returnCode == 606) {
						this.showModal = true
						this.showContent = res.data.message
						return;
					}
					
				})
			}
		},
		cancel(){
			this.oldPassword = '';
			this.newPassword = '';
		},
		logout() {
			this.$api.logout().then((res) => {
				if(res.data.returnCode == '200') {
					localStorage.clear();
					uni.navigateTo({
						url:'/pages/login/login'
					})
				}
			})
		}
	}
}